<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>转手商城后台-增加用户</title>
		<link rel="stylesheet" type="text/css" href="../../static/layui/css/layui.css" />
		<link rel="stylesheet" type="text/css" href="../../static/css/admin.css" />

		<script src="../../static/js/public/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../static/js/public/jquery.session.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../static/js/public/vue.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../static/js/public/axios.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../static/js/public/util.js" type="text/javascript" charset="utf-8"></script>

		<script src="../../static/layui/layui.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../static/js/common.children.js" type="text/javascript" charset="utf-8"></script>	
	</head>

	<body>
		<form class="layui-form column-content-detail" id="add" @submit.prevent="onSubmit">
			<div class="layui-tab">
				<ul class="layui-tab-title">
					<li class="layui-this">增加用户</li>
				</ul>
				<div class="layui-tab-content top-10">
					<div class="layui-tab-item layui-show">
						<div class="layui-form-item">
							<label class="layui-form-label">昵称：</label>
							<div class="layui-input-block">
								<input type="text" v-model="name" name="name" lay-verify="required" placeholder="请输入昵称" autocomplete="off"
								 class="layui-input">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">电话：</label>
							<div class="layui-input-block">
								<input type="text" v-model="phone" name="phone" placeholder="请输入电话" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">邮箱：</label>
							<div class="layui-input-block">
								<input type="text" v-model="email" name="email" placeholder="请输入邮箱" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">性别：</label>
							<div class="layui-input-block">
								<select name="sex" ref="select" id="select">
									<option value="">请选择性别</option>
									<option value="男" selected="">男</option>
									<option value="女">女</option>
								</select>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">收货地址：</label>
							<div class="layui-input-block">
								<input type="text" v-model="address" name="address" placeholder="请输入收货地址" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">密码：</label>
							<div class="layui-input-block">
								<input type="password" v-model="password" name="password" lay-verify="required" placeholder="请输入密码"
								 autocomplete="off" class="layui-input">
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="layui-form-item" style="padding-left: 10px;">
				<div class="layui-input-block">
					<button class="layui-btn layui-btn-normal" lay-submit lay-filter="formDemo" @click="addSubmit()">立即提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</form>

		<script type="text/javascript">
			var vm = new Vue({
				el: '#add',
				data: {
					name: "",
					phone: "",
					email: "",
					sex: "",
					address: "",
					password: ""
				},
				methods: {
					addSubmit() {
						var _this = this;
						var optionVal = this.$refs.select.value;
						
						axios({
							method: 'post',
							url: getRootURL() + 'admin/add-user',
							data: {
								name: _this.$data.name,
								phone: _this.$data.phone,
								email: _this.$data.email,
								sex: optionVal,
								address: _this.$data.address,
								password: _this.$data.password
							},
							headers: {
								'Content-Type': 'application/json',
								'Authorization': $.session.get("token")
							}
						}).then(function(res) {
							console.log(res);

							if (res.data.status >= 0) {
								alert(res.data.msg, function() {
									window.parent.refresh(); //父页面刷新
									
									var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
									parent.layer.close(index);//关闭窗口
								});
							} else {
								alert(res.data.msg);
							}

						}).catch(function(err) {
							alert(err);
						});
					},
					onSubmit() {
						//防止form冒泡
						return false;
					}
				}

			})
		</script>

	</body>

</html>
